home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
pascal3
/
pro9
/
cpexec.asm
< prev
next >
Wrap
Assembly Source File
|
1988-04-17
|
3KB
|
111 lines
IFDEF M286 ; "/DM286" on the MASM command line will
.286 ; assemble for 80186/286/386 processors
ELSE
.8086
ENDIF
DATA SEGMENT WORD PUBLIC
EXTRN WindMin: WORD ; Pascal variables
EXTRN WindMax: WORD
EXTRN TextAttr: WORD ; Actually a byte but can't PUSH byte
EXTRN SPTable: WORD
EXTRN CurrentTask: WORD
EXTRN ActiveTasks:WORD
EXTRN WhereXY:FAR ; Pascal routines
EXTRN GoToXYAbs:FAR
EXTRN CursorTypeSL:FAR
EXTRN SetCursorSize:FAR
DATA ENDS
CODE SEGMENT BYTE PUBLIC
ASSUME CS:CODE, DS:DATA
PUBLIC TaskSwitch
TaskSwitch PROC FAR ; procedure TaskSwitch;
PUSHF ; Save registers
PUSH DS
IFDEF M286
PUSHA ; 80186/80286/386 only
ELSE
PUSH AX ; PUSHA equivalent for 8086/88
PUSH CX
PUSH DX
PUSH BX
PUSH SP
PUSH BP
PUSH SI
PUSH DI
ENDIF
PUSH ES
CALL CursorTypeSL ; Get current cursor type
PUSH AX
CALL WhereXY ; Get current cursor position
PUSH AX
PUSH WindMin
PUSH WindMax
PUSH TextAttr
LEA DI,SPTable ; DI := SPTable
MOV BX,[CurrentTask] ; BX := current task
MOV CL,2 ; 4 bytes per entry
SHL BX,CL
MOV [BX+DI],SP ; Save current stack pointer
MOV [BX+DI+2],SS
LEA SI,ActiveTasks
SHR BX,CL ; Restore BX
FINDNEXT:
INC BX ; Next task number
AND BX,0FH ; Maximum of 16 tasks
CMP BYTE PTR [BX+SI],0 ; Task installed?
JZ FINDNEXT ; No, keep incrementing BX
MOV [CurrentTask],BX ; Save new task number
SHL BX,CL ; 4 bytes per entry
CLI ; No interrupts while we ...
MOV SP,[BX+DI] ; ... load stack pointer with new task
MOV SS,[BX+DI+2]
STI ; Interrupts ok now
POP TextAttr ; Restore text attributes
POP WindMax ; Restore window parameters
POP WindMin
POP DX ; Restore cursor position
PUSH DX
MOV AL,DH
PUSH AX
CALL GoToXYAbs
POP DX ; Restore cursor type
MOV AL,DH
PUSH AX
PUSH DX
CALL SetCursorSize
POP ES ; Restore registers
IFDEF M286
POPA ; 80186/286/386 only
ELSE
POP DI ; POPA equivalent for 8086/88
POP SI
POP BP
POP BX ; Not a typo, SP is discarded
POP BX
POP DX
POP CX
POP AX
ENDIF
POP DS
POPF
RET ; Activate next task
TaskSwitch ENDP
CODE ENDS
END